// #include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
bool bowl[30];
bool flip[30];
const int n=21;
const int INF=999;
int ans[2];

void solve() {
  // filp the first
  flip[1]=ans[0]=1;
  for(int i=2; i<n; ++i)
    if(flip[i] = (flip[i-2]^flip[i-1]^bowl[i-1]))
      ans[0]++;
  if(flip[19]^flip[20]^bowl[20])ans[0]=INF;

  // don't flip the first
  flip[1]=ans[1]=0;
  for(int i=2; i<n; ++i)
    if(flip[i] = (flip[i-2]^flip[i-1]^bowl[i-1]))
      ans[1]++;
  if(flip[19]^flip[20]^bowl[20])ans[1]=INF;

  cout<<min(ans[0], ans[1])<<'\n';
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  for(int i=1; i<n; ++i)cin>>bowl[i];
  solve();
  return 0;
}
